package xin.nick.demo;

import org.dom4j.DocumentException;
import xin.nick.demo.entity.User;
import xin.nick.demo.mapper.UserMapper;
import xin.nick.persistence.core.Resources;
import xin.nick.persistence.core.builder.SqlSessionFactoryBuilder;
import xin.nick.persistence.core.session.SqlSession;
import xin.nick.persistence.core.session.SqlSessionFactory;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @auther Nick inickning@outlook.com
 * @date: 2021/5/5 17:52
 * @description:
 */
public class MyPersistenceApp {

    public static void main(String[] args) throws PropertyVetoException, DocumentException, ClassNotFoundException {
        System.out.println("Hello");
        InputStream inputStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryBuilder.build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSqlSession();
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        // 查询全部
        System.out.println(userMapper.selectList());
        // 根据id 查
//        User user = new User();
//        user.setId(2);
//        System.out.println(userMapper.selectById(user));
        // 更新
//        User user = new User();
//        user.setId(2);
//        user.setName("张三5");
//        user.setAge(25);
//        System.out.println(userMapper.updateById(user));
//        System.out.println(userMapper.selectById(user));

        // 插入
//        User userInsert = new User();
//        userInsert.setName("赵六");
//        userInsert.setAge(26);
//        System.out.println(userMapper.insert(userInsert));
//        System.out.println(userMapper.selectList());

        // 删除
//        User userDelete = new User();
//        userDelete.setId(11);
//        System.out.println(userMapper.deleteById(userDelete));
//        System.out.println(userMapper.selectList());
    }



}
